package brokers;


import models.SLA;

import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.SimEvent;

import util.Globals;

public class PDPBroker extends SkeletonBroker {

	private double t1 = 0;
	private double t2 = 0;

	public PDPBroker(String name, double endSimulationTime, SLA sla1, SLA sla2) throws Exception {
		super(name, endSimulationTime, sla1, sla2);
	}
	

	/**
	 * Process a cloudlet return event.
	 *
	 * @param ev a SimEvent object
	 *
	 * @pre ev != $null
	 * @post $none
	 */
	@Override
	protected void processCloudletReturn(SimEvent ev) {

		super.processCloudletReturn(ev);
		
		if(((Cloudlet)ev.getData()).getClassType() == 1){
			t1 = (double)met1/(double)total1;
			priority1 = sla1.getY() - t1;
		}

		if(((Cloudlet)ev.getData()).getClassType() == 2){
			t2 = (double)met2/(double)total2;
			priority2 = sla2.getY() - t2;
		}
		

		if (mycloudletList.size()>0 && CloudSim.clock() < endSimulationTime && returned < Globals.SIMULATION_STABILIZATION_CLOUDLETS + Globals.SIMULATION_CLOUDLETS) {
			submitCloudlets();
		}
	}

}
